<template>
  <div class="app">
    <!-- 按钮区 -->
    <ul>
      <li v-for="(item,index) in btnlist" :key="item.id" 
      :class="{active:AIndex==item.id?true:false}"
      @click="toggle(index)">{{item.title}}</li>
    </ul>
    <!-- 组件区 -->
    <!-- 动态组件渲染区 -->
    <article>
    <component :is="comID"></component>
    </article>
  </div>
  
</template>

<script>
import {markRaw,shallowRef} from 'vue';
import MyCart from './components/MyCart.vue';
import TallCom from './components/TallCom.vue';
import TallFather from './components/TallFather.vue';


// 选项式API
export default {
  name: 'App',
  data(){
    return{
      
      AIndex : 3,// 默认显示的id
      comID : shallowRef(TallFather),// 默认加载的组件
      btnlist:[
        {id:1,title:'购物车', com : markRaw(MyCart)},
        {id:2,title:'仿QQ', com : markRaw(TallCom)},
        {id:3,title:'仿Vx', com : markRaw(TallFather)},
      ]
    }
  },
  methods:{
    toggle(i){
      this.AIndex = this.btnlist[i].id;
      this.comID = this.btnlist[i].com;
    }
  }
}
</script>

<style scoped>
*{
  margin: 0;
  padding: 0;
  list-style-type: none;
}
.app{
  width: 100%;
  overflow: hidden;
}
.app ul{
  width: 100%;
  height: 70px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid orange;
}
.app ul li{
  width: 150px;
  height: 70px;
  border-radius: 6px;
  background-color: white;
  color: orange;
  margin-right: 15px;
  text-align: center;
  line-height: 70px;
}
.app ul li:hover{
  cursor: pointer;
  
}

.app ul li.active{
  background-color: rgb(0, 108, 108);
  color: white;
  font-weight: bold;
}
</style>
